/*
 * You need to finish the main (just if and else), readEmployeeData, printEmployeeData
 *    and printAll methods
 *
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */

/**
 * @author Andrew Shore
 * @author clint
 *
 * A simple test file to test the Person->Employee inheritance hierarchy.
 */

import java.util.Scanner;

public class EmployeeTest {
	/**
	 * Represents the default number of Employee objects to be represented.
	 */
	public static final int DEFAULTSIZE = 6;

	/**
	 * precondition: the parameter array of Employees, <i>e</> has been
	 * intialized. The parameter <i>numberOfEmployees</i> represents the number
	 * of employees that will be created and added to the array of Employees.
	 * Note: this does not mean that any Employee objects were created just the
	 * spaces in the array.
	 * 
	 * postcondition: The user is prompted to enter information in for 
	 * <i>numberOfEmployees</i> that can be either hourly employees or
	 * salaried employees, which are then created and placed into sequential
	 * slots in our Employee array.
	 */
	public static void readEmployeeData(Employee[] e, int numberOfEmployees,
			Scanner keyboard) {
		// start a loop so you can make numberOfEmployees

		// inside loop, prompt the user for whether they want to add an
		// HourlyEmployee or a
		// salaried employee
		for(int index=0; index<e.length; index++){
		boolean isContinue=true;
			while(isContinue){
				
				System.out.println("Do you want to add an Hourly Employee or a Salaried Employee?(Enter hourly or salaried)");
				String choice=keyboard.next();
				keyboard.nextLine();
			if(choice.equalsIgnoreCase("hourly")){
				for(index=0; index<e.length; index++){
					
				
					if(e[index]==null&&index<e.length){
						
						System.out.println("What is the employee's name?");
						String name=keyboard.nextLine();
						System.out.println("What is the employee's age?");
						int age=keyboard.nextInt();
						System.out.println("What is the employee's job title?");
						String jobTitle=keyboard.next();
						keyboard.nextLine();
						System.out.println("What is the employee's hourly pay?");
						double hourlyPay=keyboard.nextDouble();
						e[index]= new HourlyEmployee(name, age, jobTitle, hourlyPay);
						
						break;
					}
			
				}
			}
			if(choice.equalsIgnoreCase("salaried")){
				for(index=0; index<e.length; index++){
					if(e[index]==null){
						
						System.out.println("What is the employee's name?");
						String name=keyboard.nextLine();
						System.out.println("What is the employee's age?");
						int age=keyboard.nextInt();
						System.out.println("What is the employee's job title?");
						String jobTitle=keyboard.next();
						keyboard.nextLine();
						System.out.println("What is the employee's salary?");
						double salary=keyboard.nextDouble();
						e[index]= new SalariedEmployee(name, age, jobTitle, salary);
						break;
					}
				
				
				}
				
			}
			if(index>=e.length-1){
				isContinue=false;
				return;
				
			}
		
		}
		}



	}

	/**
	 * precondition: paramater <i>name</i> is not null( easy to check and you
	 * should), and the array of Employee objects <i>e</i> has been intialized.
	 * 
	 * postcondition: if the <i>name</i> is present as an Employee object, then
	 * that Employee's information will be printed to the console. If the
	 * <i>name</i> is not present, then \"Name not found\" will be printed to
	 * the console.
	 */
	public static void printEmployeeData(String name, Employee[] e) {
		// add your implementation here
		for(int index=0; index<e.length; index++){
			if(e[index]!=null){
				if(name.equalsIgnoreCase(e[index].getName())){
					System.out.println("*************************");
					e[index].print();
					
					break;
					
				}
				
			}
		}
	}

	/**
	 * precondition: the array of Employee objects <i>employee</i> has been
	 * intialized.
	 * 
	 * postcondition: all of the Employee's information will be printed to the
	 * console.
	 */
	public static void printAll(Employee[] employee) {
		//add your implementation here

		for(int index=0; index<employee.length; index++){
		
			if(employee[index]==null){
			System.out.println("null");
			}
			else{
				System.out.println("*************************");
				employee[index].print();
				
			}
		}
		
	}

	

	public static void main(String[] args) {
		Scanner keyboard = new Scanner(System.in);
				
		// prompt the user for the number of employees to be created
		System.out.print("Welcome, how many Employees will you be creating today: ");
		// get the number of employees from the user
		int numberOfEmployees = keyboard.nextInt();
		keyboard.nextLine();	// clears the '\n' char

		// then create the array the proper size
		Employee[] employee = new Employee[numberOfEmployees];

		EmployeeTest.readEmployeeData(employee, numberOfEmployees, keyboard);
		
		

		while (true) {
			
			System.out.println("Enter an employee's name to search (\"all\" to print all, \"exit\" to exit):");
			String choice = keyboard.nextLine();
			
			// if choice equals "all" call printAll(), if choice equals "exit"
			// break else call printEmployeeData()
			if(choice.equalsIgnoreCase("all")){
				//what method should you call here?
				printAll(employee);
			}
			else if(choice.equalsIgnoreCase("exit")){
				System.out.println("Thank you for using the program.");
				break;
			}
			else{
				//if the choice is not all or exit, then the user must
				//  have entered a name to lookup, so what method should
				//  you call here?
				EmployeeTest.printEmployeeData(choice, employee);
				
			}
			
			
			
		}
	}
}

